package com.log.service.Impl;

import com.log.common.vo.ResStatus;
import com.log.common.vo.ResultVo;
import com.log.dao.LogEmployeerMapper;
import com.log.dao.LogUserMapper;
import com.log.pojo.LogEmployeer;
import com.log.pojo.LogUser;
import com.log.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Author: 林永智
 * @Date: 2023/10/19/19:43
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
//    private LogEmployeerMapper logEmployeerMapper;
    private LogUserMapper logUserMapper;
    @Override
    public ResultVo loginByTel(String username, String password) {
        Example example=new Example(LogUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username",username);
        List<LogUser> list = logUserMapper.selectByExample(example);
        if(list.size()>0)
        {
            //判断密码
            LogUser logUser = list.get(0);
            boolean equals = logUser.getPassword().equals(password);
            if (equals){
                return new ResultVo(ResStatus.OK,"登录成功",logUser);
            }else {
                return new ResultVo(ResStatus.NO,"密码错误",null);
            }
        }else{
            return new ResultVo(ResStatus.OK,"用户名不存在",null);
        }

    }
}
//    @Override
//    public ResultVo register(String phone, String password) {
//        Example example=new Example(LogEmployeer.class);
//        Example.Criteria criteria = example.createCriteria();
//        criteria.andEqualTo("logEmployeerPhone",phone);
//        List<LogEmployeer> list = logEmployeerMapper.selectByExample(example);
//        if (list.size()>0){
//            //电话已存在
//            return new ResultVo(ResStatus.NO,"该用户已存在",null);
//        }else {
//            //电话未注册
//            LogEmployeer logEmployeer = new LogEmployeer();
//            logEmployeer.setLogEmployeerPhone(phone);
//            logEmployeer.setLogEmployeerPass(password);
//            logEmployeerMapper.insert(logEmployeer);
//            return new ResultVo(ResStatus.OK,"注册成功",null);
//        }
//    }

